#!/bin/bash
function configurePackages() {
    installer=$1
    action=$2
    packageName=$3
    if [ "$installer" = "yum" ]; then
        if [ "$action" = "install" ]; then
            yum install -y $packageName
            if [ $? -ne 0 ]; then
                echo "Package install failed. Please check your command"
                exit 1
            fi
        elif [ "$action" = "uninstall" ]; then
            yum remove -y $packageName
            if [ $? -ne 0 ]; then
                echo "Package uninstall failed. Please check your command"
                exit 1
            fi
        else
            echo "Package command must be install or uninstall"
            exit 1
        fi
    elif [ "$installer" = "apt-get" ]; then
        if [ "$action" = "install" ]; then
            apt-get -y install $packageName
            if [ $? -ne 0 ]; then
                echo "Package install failed. Please check your command"
                exit 1
            fi
        elif [ "$action" = "uninstall" ]; then
            apt-get -y remove $packageName
            if [ $? -ne 0 ]; then
                echo "Package uninstall failed. Please check your command"
                exit 1
            fi
        else
            echo "Package command must be install or uninstall"
            exit 1
        fi
    else
        echo "Unknown package installer. Only support yum/apt-get"
        exit 1
    fi
}
  
configurePackages {{installer}} {{action}} {{packageName}}